package com.ruoyi.project.business.iotchip.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.business.iotchip.entity.Chip;
import com.ruoyi.project.business.iotchip.request.ListChipRequest;
import com.ruoyi.project.business.iotchip.request.AddChipRequest;
import com.ruoyi.project.business.iotchip.response.ChipResponse;
import com.ruoyi.project.business.iotchip.service.IChipService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.model.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 芯片设备基本信息管理Controller
 * 
 * @author ${author}
 * @date 2024-07-19
 */
@RestController
@RequestMapping("/business/iotchip")
public class ChipController extends BaseController {
    @Autowired
    private IChipService chipService;

    /**
     * 查询芯片设备基本信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:iotchip:list')")
    @GetMapping("/list")
    public TableDataInfo list(ListChipRequest request) {
        startPage();
        Long tenantId = getTenantId();
        Long userId = getUserId();
        List<ChipResponse> list = chipService.selectChipList(request, userId, tenantId);
        return getDataTable(list);
    }

    /**
     * 导出芯片设备基本信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:iotchip:export')")
    @Log(title = "芯片设备基本信息管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ListChipRequest request) {
        Long tenantId = getTenantId();
        Long userId = getUserId();
        List<ChipResponse> list = chipService.selectChipList(request, userId, tenantId);
        ExcelUtil<ChipResponse> util = new ExcelUtil<>(ChipResponse.class);
        return util.exportExcel(list, "iotchip");
    }

    /**
     * 获取芯片设备基本信息管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:iotchip:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(chipService.selectChipById(id));
    }

    /**
     * 新增芯片设备基本信息管理
     */
    @PreAuthorize("@ss.hasPermi('business:iotchip:add')")
    @Log(title = "芯片设备基本信息管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AddChipRequest request) {
        Long tenantId = getTenantId();
        Long operatorId = getUserId();
        return toAjax(chipService.insertChip(request, operatorId, tenantId));
    }

    /**
     * 修改芯片设备基本信息管理
     */
    @PreAuthorize("@ss.hasPermi('business:iotchip:edit')")
    @Log(title = "芯片设备基本信息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Chip chip) {
        Long tenantId = getTenantId();
        Long operatorId = getUserId();
        return toAjax(chipService.updateChip(chip, operatorId, tenantId));
    }

    /**
     * 删除芯片设备基本信息管理
     */
    @PreAuthorize("@ss.hasPermi('business:iotchip:remove')")
    @Log(title = "芯片设备基本信息管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        Long tenantId = getTenantId();
        Long operatorId = getUserId();
        return toAjax(chipService.deleteChipByIds(ids, operatorId, tenantId));
    }
}
